package com.elloe.数组.移除元素;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2022-04-02 19:08
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public class RemoveEle2 {
    public static void main(String[] args) {
        // 快慢指针

        // 测试集
        int[] nums = {0,1,2,3,3,0,4,2};
        int val = 2;

        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.length; fastIndex++){
            if (nums[fastIndex] != val){
                nums[slowIndex] = nums[fastIndex];
                slowIndex++;
            }
        }
        System.out.println(slowIndex);
    }
}
